package com.glsc.ngateway.common.base.converter.flowable;

import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableDemandDto;
import com.glsc.ngateway.common.base.domain.mysql.flowable.FlowableDemand;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class FlowableDemandConverter {
    @Nullable
    public static FlowableDemand dto2Domain(FlowableDemandDto dto) {
        return Objects.isNull(dto) ? null : FlowableDemand.builder()
                .department(dto.getDepartment())
                .systemId(dto.getSystemId())
                .staff(dto.getStaff())
                .createTime(dto.getCreateTime())
                .originalStaff(dto.getOriginalStaff())
                .originalStaffName(dto.getOriginalStaffName())
                .demandType(dto.getDemandType())
                .demandEmergeLevel(dto.getDemandEmergeLevel())
                .demandDetail(dto.getDemandDetail())
                .demandDocument(dto.getDemandDocument())
                .demandUrl(dto.getDemandUrl())
                .processInstanceId(dto.getProcessInstanceId())
                .opTime(dto.getOpTime())
                .solutionGeneral(dto.getSolutionGeneral())
                .solutionDocument(dto.getSolutionDocument())
                .onlineinfo(dto.getOnlineinfo())
                .arrangeinfo(dto.getArrangeinfo())
                .requestId(dto.getRequestId())
                .oaPdfFile(dto.getOaPdfFile())
                .demandLevel(dto.getDemandLevel())
                .build();
    }

    @Nullable
    public static List<FlowableDemand> dto2Domain(List<FlowableDemandDto> dto) {
        return CollectionUtils.isEmpty(dto) ? null: dto.stream().map(FlowableDemandConverter::dto2Domain).collect(Collectors.toList());
    }

    @Nullable
    public static FlowableDemandDto domain2Dto(FlowableDemand domain) {
        return Objects.isNull(domain) ? null : FlowableDemandDto.builder()
                .department(domain.getDepartment())
                .systemId(domain.getSystemId())
                .staff(domain.getStaff())
                .createTime(domain.getCreateTime())
                .originalStaff(domain.getOriginalStaff())
                .originalStaffName(domain.getOriginalStaffName())
                .demandType(domain.getDemandType())
                .demandEmergeLevel(domain.getDemandEmergeLevel())
                .demandDetail(domain.getDemandDetail())
                .demandDocument(domain.getDemandDocument())
                .demandUrl(domain.getDemandUrl())
                .processInstanceId(domain.getProcessInstanceId())
                .opTime(domain.getOpTime())
                .solutionGeneral(domain.getSolutionGeneral())
                .solutionDocument(domain.getSolutionDocument())
                .onlineinfo(domain.getOnlineinfo())
                .arrangeinfo(domain.getArrangeinfo())
                .requestId(domain.getRequestId())
                .oaPdfFile(domain.getOaPdfFile())
                .demandLevel(domain.getDemandLevel())
                .build();
    }

    @Nullable
    public static List<FlowableDemandDto> domain2Dto(List<FlowableDemand> domain) {
        return CollectionUtils.isEmpty(domain) ? null: domain.stream().map(FlowableDemandConverter::domain2Dto).collect(Collectors.toList());
    }
}
